//
//  SEGIntegratedServicesManager.m
//  TableDemo
//
//  Created by Clavis on 2019/6/13.
//  Copyright © 2019 Clavis. All rights reserved.
//

#import "SEGIntegratedServicesManager.h"

@implementation SEGIntegratedServicesManager

/**
 请求园区服务列表

 @param finished 回调
 */
+ (void)requestIntegratedServiceListWithFinished:(SEGNetworkReponse)finished {
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/project-operation-app/service/getListByCommunityIdAndType",nil];
    NSDictionary *param = @{@"communityId" : kAccountCommunityID,
                            @"serviceTypeCode" : @"enterpriseExclusive"
                            };
    
    [SEGHTTPBusinessManager seg_requestJSONWithMethod:POST URLString:urlString parameters:param finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        finished(isSuccessed, result, codeType, errorMessage);
    }];
}


/**
 请求园区服务表单

 @param finished finished
 */
+ (void)requestIntegratedServiceFromWithFinished:(SEGNetworkReponse)finished {
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/project-operation-app/enterpriseApply/queryFormContentByCommunityId",nil];
    NSDictionary *param = @{@"communityId" : kAccountCommunityID
                            };
    
    [SEGHTTPBusinessManager seg_requestWithMethod:GET URLString:urlString parameters:param finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        finished(isSuccessed, result, codeType, errorMessage);
    }];
}

/**
 提交园区服务申请

 @param formList 表单
 @param serviceListModel 服务model
 @param finished finished
 */
+ (void)requestApplyIntegratedServiceWithFormList:(NSArray<SEGIntegratedServicesApplyFromModel *> *)formList serviceListModel:(SEGIntegratedServicesListModel *)serviceListModel finished:(SEGNetworkReponse)finished {
    NSMutableArray *formArray = [NSMutableArray array];
    for (SEGIntegratedServicesApplyFromModel *subForm in formList) {
        NSDictionary *formDic = @{@"fieldName": subForm.name,
                                  @"fieldValue" : subForm.value,
                                  @"sort" : subForm.sort
                                  };
        [formArray addObject:formDic];
    }
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/project-operation-app/enterpriseApply/add",nil];
    NSMutableDictionary *mParams = [@{@"appType": @"3",
                                      @"appId" : [SEGPlatformManager segAppPlatformCode],
                                      @"appName" : kAppName,
                                      @"serviceTypeId" : serviceListModel.modelId ?: @"",
                                      @"serviceTypeName" : serviceListModel.name ?: @"",
                                      @"communityId" : kAccountCommunityID,
                                      @"detail" : formArray
                                    } mutableCopy];
    [SEGHTTPBusinessManager seg_requestJSONWithMethod:POST URLString:urlString parameters:mParams finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        finished(isSuccessed, result, codeType, errorMessage);
    }];
    
}

@end
